package ua.net.gm.server.walker.dummy;

import ua.net.gm.server.condition.ICondition;
import ua.net.gm.server.condition.IConditionContext;
import ua.net.gm.server.walker.WalkerConditionContext;

/**
 *
 * @author Yason
 */
public class StopOnFailCondition implements ICondition
{
    private final int fail;
    
    private final int failStreak;

    /**
     * Make true stop condition on selected fail counters levels
     * @param fail 0 or less to ignore or stop on value or more
     * @param failStreak 0 or less to ignore or stop on value or more
     */
    public StopOnFailCondition(int fail, int failStreak)
    {
        this.fail = fail;
        this.failStreak = failStreak;
    }
    
    @Override
    public boolean permit(IConditionContext context)
    {
        WalkerConditionContext cont = (WalkerConditionContext) context;
        int f = cont.getWalker().getFailCount();
        int fs = cont.getWalker().getLastFailStreakCount();
        return (fail > 0 && f >= fail) 
                || (failStreak > 0 && fs >= failStreak);
    }

    public int getFail()
    {
        return fail;
    }

    public int getFailStreak()
    {
        return failStreak;
    }
}